﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 02/01/2009
// Time: 11:37
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of Address.
	/// </summary>
	public class Address : csharp.common.DefaultClass, csharp.common.IClass
	{
		#region private declarations
			private String _person_id;
			private String _neighborhood_id;
			private String _type_id;
			private String _address;
			private String _complement;
			private String _reference;
			private String _number;
			private String _enable;
			private String _register_date; 
		#endregion
		
		public Address()
		{
			gsql.table = "common.address";
			_sequence  = "common.address_address_id_seq";
		}
			
		#region properties
			public string personId
			{
				get { return  _person_id; }
				set { _person_id = value; }
			}
			
			public string neighborhoodId 
			{
				get { return _neighborhood_id; }
				set { _neighborhood_id = value; }
			}
			
			public string typeId 
			{
				get { return _type_id; }
				set { _type_id = value; }
			}
			
			public string address 
			{
				get { return _address; }
				set { _address = value; }
			}
			
			public string complement 
			{
				get { return _complement; }
				set { _complement = value; }
			}
			
			public string reference 
			{
				get { return _reference; }
				set { _reference = value; }
			}
			
			public string number 
			{
				get { return _number; }
				set { _number = value; }
			}
			
			public bool enable 
			{
				get { return Convert.ToBoolean(_enable); }
				set { _enable = Convert.ToString(value); }
			}
			
			public string registerDate 
			{
				get { return _register_date; }
				set { _register_date = value; }
			}
		
		#endregion
		
		public void clear()
		{
			_id					= String.Empty;
			_person_id			= String.Empty;
			_neighborhood_id	= String.Empty;
			_type_id				= String.Empty;
			_address				= String.Empty;
			_complement			= String.Empty;
			_reference			= String.Empty;
			_number				= String.Empty;
			_enable				= Boolean.TrueString;
			_register_date		= String.Empty;
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id					= dr["address_id"].ToString();
			_person_id			= dr["address_person_id"].ToString();
			_neighborhood_id	= dr["address_neighborhood_id"].ToString();
			_type_id				= dr["address_type_id"].ToString();
			_address				= dr["address_address"].ToString();
			_complement			= dr["address_complement"].ToString();
			_reference			= dr["address_reference"].ToString();
			_number				= dr["address_number"].ToString();
			_enable				= dr["address_enable"].ToString();
			_register_date		= dr["address_register_date"].ToString();			
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id						, "address_id");
			gsql.setValue(_person_id			, "address_person_id");
			gsql.setValue(_neighborhood_id	, "address_neighborhood_id");
			gsql.setValue(_type_id				, "address_type_id");
			gsql.setValue(_address				, "address_address");
			gsql.setValue(_complement			, "address_complement");
			gsql.setValue(_reference			, "address_reference");
			gsql.setValue(_number				, "address_number");
			gsql.setValue(_enable				, "address_enable");
			//gsql.setValue(Convert.ToDateTime(_register_date).ToString("yyyy/MM/dd")	, "address_register_date");
		}
		
 		public bool get(String personId, String typeId)
 		{
			gsql.prepare();
			gsql.setValue("","*");
			gsql.commandType = common.GenerateSql.TCommandType.CMD_SELECT;
			gsql.conditionalWhere= "address_person_id = '"+personId+"' ";
			gsql.conditionalWhere= "address_type_id = '"+typeId+"' ";
			
			if (gsql.execute())
			{
				if (gsql.getRowCount() > 0)
				{
					get(gsql.getRow(0));
					return true;
				}
			}
			return false;	 			
 		}		
	}
}
